<%@ page import="java.util.List" %>
<%@ page import="com.bdqn.pojo.Newtable" %>
<%@ page import="com.bdqn.dao.NewDao" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2023/8/18
  Time: 11:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%
    String index=request.getParameter("index");
    String nn=request.getParameter("nn")==null?"":request.getParameter("nn");
    int in=index==null?1:new Integer(request.getParameter("index"));
    List<Newtable> list= NewDao.getlist(in,nn);
    int pagecount=NewDao.count(nn);
    request.setAttribute("nn",nn);
%>
<html>


<head>
    <title>Title</title>

    <script type="text/javascript" src="jquery3.js"></script>
    <script>
        $(function (){
           $("td").mouseover(function (){
               $(this).css("color","red");
               $(this).css("font-size","50px");
           });
            $("td").mouseleave(function (){
                $(this).css("color","");
                $(this).css("font-size","30px");
            });
            $("tr:odd").css("background-color","pink");
        });
    </script>
    <style>
        table{
            border: 1px solid red;
            margin: 0px auto;
            border-collapse: collapse;
            width: 900px;
            font-size: 30px;
            text-align: center;
            color:blue;
        }
        td{
            border: 1px solid red;
        }
        #main
        {
            border: 1px solid black;
            width: 1200px;
            height: 700px;
            margin: 0px auto;
        }
        #top
        {
            border: 1px solid black;
            width: 1200px;
            height: 200px;
        }
        #bom
        {
            border: 1px solid black;
            width: 1200px;
            height: 500px;
        }
        #left
        {
            border: 1px solid black;
            width: 200px;
            height: 500px;
            float: left;
        }
        #rig
        {
            border: 1px solid black;
            width: 900px;
            height: 500px;
            float:right;
        }
    </style>
</head>
<body>


<jsp:include page="Top.jsp"></jsp:include>

            <table>
                <tr>
                    <td colspan="6">
                        <input type="text" value="${nn}" id="sss">
                        <input type="button" onclick="search();" value="搜索">
                        <input type="button" onclick="add();" value="添加">
                        <input type="button" onclick="delall();" value="全部删除">
                    </td>
                </tr>
                <% for(Newtable o:list) {%>
                <tr>
                    <td>
                        <input type="checkbox" value="<%=o.getId()%>" name="ck">
                        <%=o.getId()%>
                    </td>
                    <td><%=o.getAuthor()%></td>
                    <td><%=o.getTitle()%></td>
                    <td><%=o.getContext()%></td>
                    <td><%=o.getName()%></td>
                    <td><a href="update.jsp?id=<%=o.getId() %>">修改</a>
                        <a onclick="del(<%=o.getId() %>)">删除</a>

                    </td>
                </tr>
                <%} %>
                <tr>
                    <td colspan="6">
                        总页数:<%=pagecount %>/当前页数<%=in %>
                        <a href="List.jsp?index=<%=in-1==0?1:in-1 %>">上一页</a>
                        <% for(int i=1;i<=pagecount;i++){ %>
                        <a href="List.jsp?index=<%=i %>&nn=${nn}"><%=i %></a>&nbsp;
                        <%} %>
                        <a href="List.jsp?index=<%=in+1>pagecount?pagecount:(in+1) %>">下一页</a>
                        <input id="vv" value="<%=in %>" type="text" style="width: 30px;">
                        <input onclick="tz();" type="button" value="跳转">
                        <script>
                            //搜索
                            function search()
                            {
                                var name=$("#sss").val();
                                window.location="/Web1/List.jsp?nn="+name;
                            }
                            //全部删除方法
                            function delall()
                            {
                                //获取所有checkbox 选中的值
                                var str="";
                                $("input[name='ck']:checked").each(function (index,obj){
                                     str+=$(obj).val()+",";
                                });
                                if(str=="")
                                {
                                    alert("请选择要删除的数据");
                                }
                                else
                                {
                                    //进行异步交互
                                    $.ajax({
                                        type:'get',
                                        url:'/Web1/ajax3',
                                        data:{str:str},
                                        success:function (data)
                                        {
                                            if(data=="ok")
                                            {
                                                //重新刷新当前页面
                                                window.location="/Web1/List.jsp";
                                            }
                                        }
                                    })
                                }
                            }
                            //修改
                            function tz()
                            {
                                var val=document.getElementById("vv").value;
                                window.location="List.jsp?index="+val;
                            }
                            //添加
                            function add()
                            {
                                window.location="add.jsp";
                            }
                            //删除
                            function del(id)
                            {
                                if(confirm("是否删除id为"+id+"的数据"))
                                {
                                    window.location="/Web1/Newdel?id="+id;
                                }
                                else {
                                    alert("取消删除");
                                }
                            }
                        </script>
                    </td>
                </tr>
            </table>


<jsp:include page="Bom.jsp"></jsp:include>


</body>
</html>
